package fr.umlv.ig.model;

import java.util.ArrayList;
import java.util.List;

public class Line {
	private final String number;
	private int numberOfStations;
	private int numberOfItineraries;
	private final List<Station> stations = new ArrayList<Station>();
	private final List<Itinerary> itineraries = new ArrayList<Itinerary>();
	
	public Line(String number) {
		if(number == null) {
			throw new NullPointerException("the number of the line is null");
		}
		this.number = number;
	}

	public String getNumber() {
		return number;
	}
	
	public int getCountStation() {
		return numberOfStations;
	}
	
	public int getCountItinerary() {
		return numberOfItineraries;
	}
	
	
	void addItinaries(Itinerary itinerary) {
		if(itinerary == null) {
			itineraries.add(itinerary);
		}
		numberOfItineraries++;
		itineraries.add(itinerary);
	}
	
	public Itinerary getItinerary(int i) {
		return itineraries.get(i);
	}


	void addStation(Station station) {
		if(station == null ) {
			throw new NullPointerException("The station is null");
		}
		numberOfStations++;
		stations.add(station);
	}
	
	Station getStation(int i) {
		if(i< 0 || i> numberOfStations) {
			throw new ArrayIndexOutOfBoundsException();
		}
		return stations.get(i);
	}
	
	public boolean contains(Station station) {
		return stations.contains(station);
	}
	
	int indexOf(Station station) {
		return stations.indexOf(station);
	}
	
	@Override
	public boolean equals(Object obj) {
		if(obj == this) {
			return true;
		}
		if(!(obj instanceof Line)) {
			return false;
		}
		Line line = (Line) obj;
		return number.equals(line.number) && numberOfStations == line.numberOfStations
			&& numberOfItineraries == line.numberOfItineraries; 
	}
	
	@Override
	public int hashCode() {
		return number.hashCode() + numberOfItineraries + numberOfItineraries;
	}
}
